package com.gxa.modules.service.operationsservice.impl;

import com.gxa.common.R;
import com.gxa.common.utils.DateUtils;
import com.gxa.modules.mapper.operationsmapper.HLCarPayMapper;
import com.gxa.modules.pojo.CarBill;
import com.gxa.modules.pojo.CarBillVo;
import com.gxa.modules.pojo.Contract;
import com.gxa.modules.service.operationsservice.HLCarPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.List;

import static com.gxa.common.utils.DateUtils.DATE_TIME_PATTERN;

/**
 * @Author hl
 * Date 2022/5/10 12:16
 */
@Service
@SuppressWarnings("all")
public class HLCarPayServiceImpl implements HLCarPayService {

    @Autowired
    HLCarPayMapper hlCarPayMapper;

    @Override
    public R addCarPayInfo(CarBill carBill) {
        R r = new R();
        String moneyTime = DateUtils.getCurrentTime(DATE_TIME_PATTERN);
        carBill.setMoneyTime(moneyTime);
        int action = hlCarPayMapper.addCarPayInfo(carBill);
        if (action < 1) {
            r.setCode(301);
            r.setMsg("添加失败！");
            return r;
        }
        r.setCode(200);
        r.setMsg("添加成功");
        return r;
    }

    @Override
    public R selectCarPayInfo(String carNumber, String linkWay, String carType, int page, int limit) {
        R r = new R();
        int index = (page - 1) * limit;
        List<CarBill> carBillList = hlCarPayMapper.selectCarPayInfo(carNumber, linkWay, carType, index, limit);
        if (carBillList.size() < 1) {
            r.setCode(301);
            r.setMsg("无数据！");
            r.setCount(hlCarPayMapper.selectCount());
            return r;
        }
        r.setCode(200);
        r.setMsg("查询成功！");
        r.setCount(hlCarPayMapper.selectCount());
        r.setData(carBillList);
        return r;
    }

    @Override
    public R updateCarPayInfoById(CarBill carBill) {
        R r = new R();
        int action = hlCarPayMapper.updateCarPayInfoById(carBill);
        if (action < 1) {
            r.setCode(301);
            r.setMsg("修改失败！");
            return r;
        }
        r.setCode(200);
        r.setMsg("修改成功");
        return r;
    }

    @Override
    public R deleteCarPayInfoById(String ids) {
        R r = new R();
        System.out.println(ids);
        String[] split = ids.split(",");
        int action = hlCarPayMapper.deleteCarPayInfoById(split);
        if (action < 1) {
            r.setCode(301);
            r.setMsg("删除失败！");
            return r;
        }
        r.setCode(200);
        r.setMsg("删除成功");
        return r;
    }

    @Override
    public R selectCarPayInfoById(int id, String carNumber) {
        R r = new R();
        CarBillVo carBillVo = hlCarPayMapper.selectCarPayInfoById(id);
        List<CarBill> carBillList = hlCarPayMapper.selectCarPayInfoByCarNumber(carNumber);
        carBillVo.setCarBillList(carBillList);
        r.setCode(200);
        r.setMsg("查询详情成功");
        r.setData(carBillVo);
        return r;
    }
}
